package com.sf.osms.dep.processor.mapper;

import java.util.Date;
import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import org.dozer.DozerConverter;

/**
 * 进行router表中某些与fvp对象中属性类型不一致的转化器
 * @author sfhq1405
 *
 */
public class DateConverter extends DozerConverter<Date,XMLGregorianCalendar> {
	
	public DateConverter() {
		super(Date.class, XMLGregorianCalendar.class);
	}
	
	@Override
	public Date convertFrom(XMLGregorianCalendar xml, Date date) {
		GregorianCalendar ca = xml.toGregorianCalendar();
        return ca.getTime();
	}

	@Override
	public XMLGregorianCalendar convertTo(Date date, XMLGregorianCalendar xml) {
		
		GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
        XMLGregorianCalendar gc = null;
        try {
            gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
        } catch (Exception e) {

             e.printStackTrace();
        }
        return gc;
		
	}

}
